﻿using System;
using System.Reflection;
using System.Collections.Generic;
using System.Data;

// declares the enum
public enum ScriptType
{
    DataObjectsScripts  = 0,
    CodeScripts         = 1,
    Debug               = 2
}

namespace CodeGenerator.kernel
{
    class AssemblyParser
    {
        private static Assembly o_Assembly;
        private static string s_Buffer;

        public AssemblyParser       (string s_AssemblyFileLongName  )
        {
            if (s_AssemblyFileLongName!=null)
                o_Assembly = Assembly.LoadFile(s_AssemblyFileLongName);
        }

        public void   Parsing       (ScriptType e_Type              )
        {
            string s_Result = "\r\n";
            
            s_Result += "Processing Assembly ...........\r\n\r\n";

            foreach (Type o_Type in o_Assembly.GetExportedTypes())
            {
                s_Result += "+Table : " + o_Type.Name.ToString() + "\r\n\r\n";

                foreach (DataType.Field o_Field in o_Type.GetCustomAttributes(false))
                {
                    s_Result += "+Field : -> PK(" +
                                                    o_Field.PrimaryKey.ToString() + "), Lenght(" +
                                                    o_Field.Lenght.ToString() + "), Precision(" +
                                                    o_Field.Precision.ToString() + "), DataType(" +
                                                    ") \r\n";
                };

            };

            s_Result += "\r\nAssembly processed ...........\r\n";

            s_Buffer = s_Result;

        }

        public void DatabaseToClass (                               )
        {
            //string s_Result = "\r\n";

            //s_Result += "Processing Assembly ...........\r\n\r\n";

            //foreach (Type o_Type in o_Assembly.GetExportedTypes())
            //{
            //    s_Result += "+Table : " + o_Type.Name.ToString() + "\r\n\r\n";

            //    foreach (DataType.Field o_Field in o_Type.GetCustomAttributes(false))
            //    {
            //        s_Result += "+Field : -> PK(" +
            //                                        o_Field.PrimaryKey.ToString() + "), Lenght(" +
            //                                        o_Field.Lenght.ToString() + "), Precision(" +
            //                                        o_Field.Precision.ToString() + "), DataType(" +
            //                                        ") \r\n";
            //    };

            //};

            //s_Result += "\r\nAssembly processed ...........\r\n";

            //s_Buffer = s_Result;

        }

        public string GetBuffer     (                               )
        {
            return s_Buffer;
        }

    }
}
